import http from '@/utils/request'
import { GoodsDetail, IGoodsItem, Stock } from './goods.types'

/**
 * 商品详情
 * @param {String} id  商品id
 * @returns {Promise} axios Promise
 */
export const findGoodsDetail = (id: string) => {
  return http<GoodsDetail>('/goods', 'get', { id: id })
}

/**
 * 热销推荐
 * @param {Object} id  商品id
 * @param {Object} limit  数量限制
 * @param {Object} type  热销类型，1为24小时，2为周榜，3为总榜，默认为1
 * @returns {Promise} axios Promise
 */
export const findGoodsHot = ({ id = '', limit = 3, type = 1 }) => {
  return http<IGoodsItem[]>('/goods/hot', 'get', { id, limit, type })
}

/**
 * 获取新的商品信息
 * @param {String} skuId - 商品SKUID
 * @returns Promise
 */
export const getNewCartGoods = (skuId: string) => {
  return http<Stock>(`/goods/stock/${skuId}`, 'get')
}

// const Test = async () => {
//   const res = await findGoodsHot({ type: 1, id: '1147023' })
//   console.log(res)
// }

// Test()
